<template>
	<div>
		<vxe-modal v-model="dialogVisible" :title="'电池包相关信息 数量:'+tableData.totalRow" width="80%" height="70%" show-zoom resize remember>
			<template #default>
				<div class="search-wrapper">
						<el-form class="search-param" ref="pageParam" :model="pageParam" label-width="100px" size="mini">
							<el-form-item label="电池包号">
								<el-input v-model="pageParam.batNo" clearable></el-input>
							</el-form-item>
							<!-- <el-form-item label="电池型号ID">
								<el-input v-model="pageParam.batModelId" clearable></el-input>
							</el-form-item> -->
							<!-- <el-form-item label="所属公司" v-if="userinfo.depid==1">
								<el-select v-model="companyact" filterable clearable @change="compancheg"  placeholder="请选择">
									<el-option v-for="item in companylist" :key="item.id" :label="item.nameCN" :value="item.id">
									</el-option>
								</el-select>
				
							</el-form-item>
							<el-form-item label="所属部门">
								<el-select v-model="depment" filterable clearable  placeholder="请选择">
									<el-option v-for="item in departmentlist" :key="item.id" :label="item.name" :value="item.id">
									</el-option>
								</el-select>
							</el-form-item> -->
							<!-- <el-form-item label="类型">
								<el-input v-model="pageParam.batTypeId" clearable></el-input>
							</el-form-item> -->
							<el-form-item style="margin-left: -60px;">
								<el-button type="primary" size="mini" class="el-icon-search" @click="pageByParam">确认查询</el-button>
							</el-form-item>
						</el-form>
					</div>
					<!-- 数据表格 -->
					<vxe-toolbar ref="xToolbar1" custom :refresh="{query: oldlist}">
						<template #buttons>
							
						</template>
					</vxe-toolbar>
					<vxe-table show-overflow :column-config="{resizable: true}" :import-config="{}" :export-config="{}"
						:print-config="{}" :loading="loading" :data="tableData.list" :height="cheight-550" size="mini"
						border stripe>
						<vxe-column type="checkbox" width="60"></vxe-column>
						<vxe-column type="seq" title="序号" width="60"></vxe-column>
						<vxe-column field="batNo" title="电池包号"></vxe-column>
						<vxe-column field="batTypeName" title="电池类型"></vxe-column>
						<vxe-column field="batModelName" title="电池型号"></vxe-column>
						<vxe-column field="createTime" title="创建时间"></vxe-column>
						<vxe-column field="creatUserName" title="创建人"></vxe-column>
						<vxe-column field="editTime" title="修改时间"></vxe-column>
						<vxe-column field="editUserName" title="修改人"></vxe-column>
						<vxe-column field="company.nameCN" title="公司"></vxe-column>
						<vxe-column field="department.name" title="运营部门"></vxe-column>
						<vxe-column field="pd" title="生产日期"></vxe-column>
						<vxe-column field="sd" title="销售日期"></vxe-column>
						<!-- <vxe-column title="操作" width="130" show-overflow>
							<template #default="{ row }">
								<vxe-button status="primary" icon="el-icon-edit" @click="addEditClick(row)"></vxe-button>
								<vxe-button status="danger" icon="el-icon-delete" @click="handleDelete(row.id)"></vxe-button>
							</template>
						</vxe-column> -->
						<!-- <vxe-column field="_X_ID" title="_X_ID"></vxe-column> -->
					</vxe-table>
					<vxe-pager background size="small" stripe :loading="loading" :current-page="pageParam.pageIndex"
						:page-size="pageParam.pageSize" :total="tableData.totalRow"
						:page-sizes="[15, 20, 100, {label: '大量数据', value: 1000}]"
						:layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']" background
						class="page-wrapper" @page-change="handleCurrentChange">
					</vxe-pager>
					
			</template>
		</vxe-modal>
	</div>
</template>

<script>
	import {
		list,
		list1,
		getcompany,
		getDepList,
		del
	} from '../batinfo/index.js'
	import {
		checkNumber
	} from '@/shop/util/validator.js'
	import request from '@/utils/request'
	import miniRedius from '@/shop/common/mini_radius.vue';
	export default {
		components: {
			miniRedius
		},
		data() {
			return {
				loading: true,
				cheight: document.documentElement.clientHeight,
				timer: [],
				pageParam: {
					batFromCompanyList: [],
					batFromDeptList: [],
					batNo: "",
					batTypeList: [],
					pageIndex: 1,
					pageSize: 15,
					token: localStorage.getItem('goods__token')
				},
				companyact: '',
				depment: '',
				companylist: [],
				departmentlist: [],
				userinfo:{},
				tableData: {
					totalRow: 0,
					list: []
				},
					dialogVisible: false,
					
				
				};
		},
		created() {
			//this.oldlist();
			let userinfo = JSON.parse(localStorage.getItem("userinfo"));
			this.userinfo = userinfo;
			if(userinfo.depid!=1){
				this.companyact = parseInt(userinfo.depid);
				this.getDepList();
			}
			this.$nextTick(() => {
				// 手动将表格和工具栏进行关联
				this.$refs.xTable1.connect(this.$refs.xToolbar1)
			})
			this.oldlist()
			this.getcompany();
		},
		
		methods: {
			handleClose(done) {
				this.resetForm('ruleForm');
				done();
			},
			open(item) {
				console.log(item)
				this.depment = item.id;
				this.oldlist();
				this.dialogVisible = true;
			},
			handleClose(done) {
				this.resetForm('ruleForm');
				done();
			},
			pageByParam() {
				this.pageParam.pageIndex = 1;
				this.pageParam.pageSize = 15;
				this.oldlist()
			},
			handleCurrentChange(val) {
				console.log(val);
				if (val.type == "size") {
					this.pageParam.pageIndex = 1;
					this.pageParam.pageSize = val.pageSize;
					this.oldlist();
				}
				if (val.type == "current") {
					this.pageParam.pageIndex = val.currentPage;
					this.pageParam.pageSize = val.pageSize;
					this.oldlist();
				}
			},
			compancheg(){
				this.depment = '';
				this.getDepList();
			},
			//公司
			async getcompany() {
				let result = await getcompany();
				this.companylist = result.obj;
			},
			//部门
			async getDepList() {
				let parm = {
					"address": "",
					"id": this.companyact,
					"nameCN": "",
					"nameEN": "",
					"remark": ""
				}
				let result = await getDepList(parm);
				this.departmentlist = result.obj;
			},
			//电池列表
			async oldlist() {
				this.loading = true;
				// if (this.timer != null && this.timer.length > 0) {
				// 	this.pageParam.stime = this.timer[0]
				// 	this.pageParam.etime = this.timer[1]
				// } else {
				// 	this.pageParam.stime = null;
				// 	this.pageParam.etime = null;
				// }
				if(this.companyact){
					this.pageParam.batFromCompanyList = [this.companyact];
				}else{
					this.pageParam.batFromCompanyList = [];
				}
				if(this.depment){
					this.pageParam.batFromDeptList = [this.depment];
				}else{
					this.pageParam.batFromDeptList = [];
				}
				let result = await list1(this.pageParam);
				//console.log("返回结果", result.data);
				this.loading = false;
				this.tableData.totalRow = result.data.total;
				this.tableData.list = result.data.list;
			
			},
			addEditClick(item) {
				this.$refs.addEdit.open(item);
			},
			// 删除
			handleDelete(id) {
				this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.del(id);
				})
			},
			async del(id) {
			
				let result = await del({
					id,
					token: this.pageParam.token
				});
				if (result.code == 1) {
					this.msgSuccess("删除成功");
					this.oldlist();
				}
				console.log(result)
			}
		}
	};
</script>

<style></style>
